#include <iostream>
#include <cmath>

using namespace std;

void Invert(char* input, int num_element)
{
	for (int i = 0; i < num_element / 2; ++i)
	{
		char tmp = input[i];
		input[i] = input[num_element - 1 - i];
		input[num_element - 1 - i] = tmp;
	}
}

void copyString1(char *input, int offset, int length, bool invert, char *output, int output_offset)
{
	int index1 = min(length, int(strlen(input) - offset));
	int index2 = min(length, int(strlen(output) - output_offset));
	while (min(index1, index2) > 0)
	{
		if (!invert)
			output[output_offset++] = input[offset++];
		else output[output_offset++] = input[offset - 1 + index1];
		index1--;
		index2--;
	}
	output[output_offset] = '\0';
}


void copyString2(char *input, int offset, int length, bool invert, char *output, int output_offset)
{
	int index1 = min(length, int(strlen(input) - offset));
	int index2 = min(length, int(strlen(output) - output_offset));
	char* tmp = new char[index1];
	memcpy(tmp, input + offset, index1);
	tmp[index1] = '\0';
	if (invert) Invert(tmp, strlen(tmp));
	memcpy(output + output_offset, tmp, min(index1, index2));
}

void copyString3(char *input, int offset, int length, bool invert, char *output, int output_offset)
{
	int index1 = min(length, int(strlen(input) - offset));
	int index2 = min(length, int(strlen(output) - output_offset));
	char* tmp = new char[index1];
	memcpy(tmp, input + offset, index1);
	tmp[index1] = '\0';
	if (invert) Invert(tmp, strlen(tmp));
	strcpy(output + output_offset, tmp);
}
void main()
{
	char st[] = "Hello World";
	char st2[] = "My name is C++";
	copyString2(st, 6, 5, true, st2, 11) ;
//Invert(st2, strlen(st2));
	cout << st2;
}